/**
 * Created by TANG on 2021/3/29.
 */
layui.config({base:'../../layui/dropdown/'})
    .use(['form','table','layedit', 'laydate' ], function() {
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.$

        $.ajax({
            type:"get",
            url:config.gatewayUri+"/"+config.deviceServiceId+"/deviceVersion/selectList",
            dataType:"json",
            success:function(result){
                if(result.code == 200){
                    $.each(result.data,function(index,item){
                        $(".versionId").append(new Option(item.name,item.versionid));
                    })
                    layui.form.render("select");
                }else{
                    layer.alert(result.msg);
                }
            },
            error:function(result){
                layer.alert(result);
            }
        })

        $("#close").click(function(){
            //window.parent.location.reload();//刷新父页面
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });

        form.on('submit(formDemo)', function(data){
            $.ajax({
                type:"put",
                url:config.gatewayUri+"/"+config.deviceServiceId+"/api/device/admin/deviceVersionUpgrade",
                data:{id:$("#deviceid").val(),versionId:$("#versionId").val()},
                dataType:"json",
                success:function(res){
                    if(res.code == 200){
                        layer.msg("版本升级成功!");
                        setTimeout(function(){
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        },2000);
                    }
                }
            })
        });
    });